<template>
  <div class="main">
    <div class="block_item">
      <div class="abos">
        <span class="left">{{ leftTitle }}</span>
        <span class="right" @click="handleClick">
          <small>{{ radioTxt }}</small>
          <i class="imgIcon"></i>
        </span>
      </div>
      <ul class="abos_list">
        <li v-for="(item, index) in listArr" :key="index" @click="removeItem(listArr, item)">
          <span>{{ item.indexOf('&') > 0 ? item.substring(0, item.indexOf('&')) : item }}</span>
          <small>X</small>
        </li>
      </ul>
    </div>
    <PopSelect :radios="radioTxt" ref="mychild" :popupShow="isPopupShow" :placeholderText="plhdText" @closePopUp="changeStatus" @sendList="listContentChange" :status="statu"></PopSelect>
  </div>
</template>

<script>
import PopSelect from '~/components/PopSelect1'
export default {
  props: {
    radioTxt: String,
    leftTitle: String,
    showArr: Array,
    plhdText: String,
    modelType: String,
  },
  components: {
    PopSelect,
  },
  data() {
    return {
      isPopupShow: false,
      listArr: [],
      sendObj: {},
      statu: '',
    }
  },
  watch: {
    showArr(arr) {
      this.listArr = arr
    },
  },
  mounted() {
    this.listArr = this.showArr
    this.sendObj.type = this.modelType
  },
  methods: {
    handleClick() {
      if (!this.$store.state.schoolProvince) {
        this.$vux.toast.text('请先选择您高考所在的省份')
        return
      }
      if (!this.$store.state.schoolLevel) {
        this.$vux.toast.text('请先选择您的目标批次')
        return
      }
      this.isPopupShow = true
      this.statu = this.modelType
      if (this.modelType == 2) {
        this.$refs.mychild.getUnivAcademy()
      }
    },
    removeItem(arr, item) {
      this.listArr = arr.filter((x) => {
        return x !== item
      })
      this.sendObj.msgList = this.listArr
      this.$emit('removeArrItem', this.sendObj)
    },
    changeStatus() {
      this.isPopupShow = false
    },
    listContentChange(arr) {
      for (const item of arr) {
        if (this.listArr.indexOf(item) == -1) {
          if (this.radioTxt == '单选') {
            this.listArr[0] = item
          } else {
            this.listArr.push(item)
          }
        }
      }
      this.isPopupShow = false
    },
  },
}
</script>

<style lang="less" scoped>
.main {
  background: #fff;
  width: 100%;
  .block_item {
    .abos {
      width: 6.3rem;
      height: 0.9rem;
      line-height: 0.9rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left {
        color: #222;
        font-size: 0.3rem;
        font-weight: bold;
        letter-spacing: 0.02rem;
      }
      .right {
        display: flex;
        align-items: center;
        small {
          // font-size: 0.26rem;
          // width: 0.52rem;
          height: 0.37rem;
          line-height: 0.37rem;
          margin-right: 0.08rem;
          font-size: 0.3rem;
          font-weight: bold;
          color: #222;
        }
      }
    }
    .abos_list {
      list-style: none;
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      align-items: center;
      padding-left: 0;
      li {
        margin: 0.1rem 0;
        padding: 0.17rem 0.2rem 0.16rem 0.2rem;
        background: #fafafa;
        color: #222;
        font-size: 0.26rem;
        border-radius: 0.1rem;
        margin-bottom: 0.1rem;
        margin-right: 0.12rem;
        small {
          margin-left: 0.2rem;
          width: 0.2rem;
          height: 0.2rem;
          color: #bbb;
        }
      }
    }
  }
}
.imgIcon {
  width: 0.4rem;
  height: 0.4rem;
  display: inline-block;
  background: url('~@/static/sprite/icon_sprites_40.png') -1.3rem -0.7rem;
  background-size: 3rem 2.4rem;
}
</style>
